#define _CRT_SECURE_NO_WARNINGS 1



class Solution {
public:
    int repFunc(int n)
    {
        int sum = 0;
        while (n)
        {
            int t = n % 10;
            sum += t * t;
            n /= 10;
        }
        return sum;
        // int a[10]={0},i=0;
        // while(n)
        // {
        //     a[i++]=n%10;
        //     n/=10;
        // }
        // int sum=0;
        // while(i--)
        // {
        //     sum+=a[i]*a[i];
        // }
        // return sum;
    }
    bool isHappy(int n) {
        int fast = n, slow = n;
        fast = repFunc(fast);
        fast = repFunc(fast);
        slow = repFunc(slow);
        while (fast != slow)
        {
            fast = repFunc(fast);
            fast = repFunc(fast);
            slow = repFunc(slow);
        }
        return fast == 1;
    }
};